﻿using Hicap.AuthorizationServer.Core.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;

namespace Hicap.AuthorizationServer.Core.Common.EFCore
{
    public class AuthorizationDbContextFactory : IDesignTimeDbContextFactory<AuthorizationDbContext>
    {
        public AuthorizationDbContext CreateDbContext(string[] args)
        {
            DbContextOptionsBuilder builder = new DbContextOptionsBuilder();
            IConfigurationRoot configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            AuthorizationDbContextConfigurer.Configure(
                builder,
                configuration.GetConnectionString(SysConsts.ConnectionName)
            );

            return new AuthorizationDbContext(builder.Options);
        }
    }
}